﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace Order
{ 
    class Program
    {
        static public void PrintOrder(List<Order> list)
        {
            for (int i = 0; i < list.ToArray().Length; i++)
            {
                WriteLine(list[i]);
                for(int j=0;j<list[i].OrderDetailsList.ToArray().Length;j++)
                WriteLine("订单明细："+list[i].OrderDetailsList[j]);
                
            }
        }

        static void Main(string[] args)
        {
            List<OrderDetail> details1 = new List<OrderDetail>()
            {
                new OrderDetail(101,"手机",1,1000),
                new OrderDetail(102,"充电器",3,10)
            };
            List<OrderDetail> details2 = new List<OrderDetail>()
            {
                new OrderDetail(201,"电脑",1,3000),
                new OrderDetail(202,"路由器",2,70)
            };
            List<OrderDetail> details3 = new List<OrderDetail>()
            {
                new OrderDetail(201,"电脑",1,3000),
                new OrderDetail(202,"音响",4,50)
            };
            List<OrderDetail> details4 = new List<OrderDetail>()
            {
                new OrderDetail(301,"鼠标",4,30),
                new OrderDetail(302,"U盘",2,70)
            };
            List<Order> myorders = new List<Order>()
           {
               new Order(1,"张三",details1),
               new Order(3,"张三",details3),
               new Order(2,"李四",details2),
           };
            OrderService service = new OrderService(myorders);
            service.list = myorders;
            WriteLine("显示当前订单：");
            PrintOrder(service.list);
            WriteLine();

            Order temp = new Order(4, "王五", details4);

            service.AddOrder(temp);
            WriteLine("增加订单：");
            PrintOrder(service.list);
            WriteLine();

            service.DeleteOrder(4);
            WriteLine("删除订单：");
            PrintOrder(service.list);
            WriteLine();

            List<Order> result= service.SearchOrder(2);
            WriteLine("搜索ID为2的订单：");
            PrintOrder(result);
            WriteLine();

            result = service.SearchOrder("CustomerID", "张三");
            WriteLine("搜索顾客为张三的订单：");
            PrintOrder(result);
            WriteLine();

            result = service.SearchOrder("ProductID", "电脑");
            WriteLine("搜索产品为电脑的订单：");
            PrintOrder(result);
            WriteLine();

            service.list.Sort();
            WriteLine("对订单排序：");
            PrintOrder(service.list);
            WriteLine();

            service.Export("s.xml");

            service.ChangeOrder(2);

            WriteLine("显示修改后订单：");
            PrintOrder(service.list);




            ReadKey();


        }
    }
}
